/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved.
 * Description: prepare filesystem
 */

#include <fstream>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include "prepare_filesystem.h"
#include <android-base/logging.h>

namespace android {
namespace init {

void prepare_filesystem() {
    struct stat buffer;
    int result = 0;

    if (lstat("/etc", &buffer) == 0 && (!S_ISLNK(buffer.st_mode))) {
        unlink("/etc/mtab");
        remove("/etc");
        symlink("/system/etc", "/etc");
    }

    if (stat("/system/bin/hook.sh", &buffer) == 0) {
        result = system("sh /system/bin/hook.sh");
        if (result != 0) {
            LOG(ERROR) << "hook.sh excute failed\n";
        }
    } else {
        LOG(ERROR) << "can not find hook.sh";
    }
}

}  // namespace init
}  // namespace android